package com.qyl.deguru.service.impl;

import java.util.Date;
import java.util.List;

import com.qyl.deguru.common.PageModel;
import com.qyl.deguru.dao.UserDao;
import com.qyl.deguru.dao.impl.UserDaoImpl;
import com.qyl.deguru.dto.User;
import com.qyl.deguru.service.UserService;
import com.qyl.deguru.utils.MD5Util;

/**
 * userService
 * @author Administrator
 *
 */
public class UserServiceImpl implements UserService {
	
	/*
	 * 实现service层方法
	 */
	private UserDao userDao = new UserDaoImpl();
	/*
	 * 实现通过用户名和密码获取用户方法
	 * 
	 */
	
	@Override
	public User getUserByUserIdAndPwd(String userId, String pwd) {
		User user =null;
		try {
			String pass_word=MD5Util.getMD5(pwd);
			//实现调用dao获得user对象		
			user = userDao.getUserByUserIdAndPwd(userId,pass_word);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	
		return user;
	}
	/*
	 * 实现通过Id获取用户方法
	 */
	@Override
	public User getUserById(String userId) {
		UserDao userDao=new UserDaoImpl();
		User user = userDao.getUserById(userId);
		return user;
	}
	/*
	 * 实现用户列表展示方法
	 */
	@Override
	public List<User> userList(User user) {	
		return userDao.userList(user);
	}
	/*
	 * 实现更新用户方法
	 */
	@Override
	public int updateUser(User user) {
		return userDao.updateUser(user);
	}
	/*
	 * 实现通过Id删除用户方法
	 */
	@Override
	public int delUserById(int id) {
		return userDao.delUserById(id);
	}
	/*
	 * 新增用户数据
	 */
	@Override
	public int addUser(User user) {
		return userDao.addUser(user);
	}
	@Override
	public List<User> getUsers(User user, PageModel pageModel) {
		return userDao.getUsers(user,pageModel);
	}
	@Override
	public int getCountByUser(User user) {
		return userDao.getCountByUser(user);
	}
	@Override
	public int delBatchUsers(int [] ids) {
		
		return userDao.delBatchUsers(ids);
	}
	@Override
	public void registerUser(User user) {
		//对用户进行加密
		try {
			String pass_word=MD5Util.getMD5(user.getPass_word());
			user.setPass_word(pass_word);
			user.setSex(0);
			user.setProvince("广东省");
			user.setCity("汕头市");
			user.setAddress("广东省-汕头市");
			user.setBirthday(new Date());
			user.setActive_status(0);
			user.setUserHeadImg("uploadComment.jpg");
			user.setCreate_date(new Date());
			if(user.getRole()==null){
				user.setRole(0);
			}
			userDao.registerUser(user);
		} catch (Exception e) {
			System.out.println("加密失败");
			e.printStackTrace();
		}
	
		
	}
//	@Override
//	public User getUser(int uid) {
//		
//		return userDao.getUser(uid);
//	}
	@Override
	public int setActiveStatus(String active_code) {
		int count=userDao.setActiveStatus(active_code);
		return count;
	}
	
	@Override
	public User getUserByEmail(String email) {
		// TODO Auto-generated method stub
		return null;
	}

}
